﻿using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;


public class SplashSceneDisplayController : ViewController
{
/*    ViewControllerNav m_DisplayControllerNav;
    ViewControllerNav ViewControllerNav
    {
        get
        {
            if (m_DisplayControllerNav == null)
            {
                m_DisplayControllerNav = new GameObject("LaunchSceneNav").AddComponent<ViewControllerNav>();
                m_DisplayControllerNav.transform.SetParent(transform);
            }

            return m_DisplayControllerNav;
        }
    }*/

    SplashPanel m_Panel;
    
    public GameObject fakeLoginLoadingAnim;
    
    public override void DidLoadView()
    {
        base.DidLoadView();
        
        if(m_Panel == null)
        {
            var pref = ResourceManager.Load<SplashPanel>(ViewPath.LaunchPanel);
            m_Panel = Instantiate<SplashPanel>(pref,transform);
            
            m_Panel.Init(OnSplashEnd);
        }
    }

    public override void OnLoadedViewEnd()
    {
        base.OnLoadedViewEnd();
    }
    

    void Preload()
    {
        
    }
    
    /// <summary>
    /// 闪屏结束
    /// </summary>
    void OnSplashEnd()
    {
        var prefab = ResourceManager.Load<GameObject>(ResourceManager.fakeLoadingAnimPath);
        if (prefab)
        {
            fakeLoginLoadingAnim = Instantiate<GameObject>(prefab, null);
        }

        GotoHome();
        //GotoBattle();
    }
    
    public override void WillHideView()
    {
        base.WillHideView();

        if (m_Panel)
        {
            Destroy(m_Panel.gameObject);
        }
        m_Panel = null;

        if(fakeLoginLoadingAnim)
            Destroy(fakeLoginLoadingAnim.gameObject);
        
        fakeLoginLoadingAnim = null;
    }

    void GotoHome()
    {
        DoActionDelay.DelayAction(.5f, () =>
        {
            //Game.Instance.rootNav.LoadDisplay<HomeSceneViewController>();
        });
    }
   

}